package com.gjy.concurrency.lock;

import org.junit.jupiter.api.Test;
import sun.misc.Unsafe;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-31 10:24:13
 */
public class UnsafeTest {

    @Test
    public void test6() {
        DecimalFormat format = new DecimalFormat("#.00");
        String s = format.format(3.3462);
        System.out.println("s = " + s);
    }

    @Test
    public void test5() {
        NumberFormat instance = NumberFormat.getInstance();
        String format = instance.format(3.30472);
        System.out.println("format = " + format);
    }

    @Test
    public void test3() {
        /*long l = LocalDateTime.of(2023, 11, 2, 13, 30, 30)
                .getLong(ChronoField.MILLI_OF_DAY);
        System.out.println("l = " + l);*/
        long l = Instant.now().toEpochMilli();
        System.out.println("l = " + l);
    }

    @Test
    public void test4() {
        long l = LocalDateTime.of(2023, 11, 2, 13, 30, 30)
                .toInstant(ZoneOffset.UTC).toEpochMilli();
        System.out.println("l = " + l);
    }

    @Test
    public void test2() {
        String format = "yyyy-M-d HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        System.out.println("sdf.format(new Date()) = " + sdf.format(new Date(1698931830000L)));
    }

    @Test
    public void test1() {
        Unsafe unsafe = Unsafe.getUnsafe();
    }
}
